#include "UpdateScenePosCallback.h"

void UpdateScenePosCallback::operator()(osg::Node* node, osg::NodeVisitor* nv){

	osg::MatrixTransform* mtLeft = dynamic_cast<osg::MatrixTransform*>( node );

	if(mtLeft){
		osg::MatrixTransform* mtLeft = dynamic_cast<osg::MatrixTransform*>( node );
		osg::Matrix mR, mT;
		if(vor){
			if(x < 80){
				if(sceneHandler->kuhCam){
					sceneHandler->setEyeZ(6.5);
					sceneHandler->setEyeY(-80.5);
					sceneHandler->setEyeX(x+30);
					sceneHandler->setCenterX(700);
				}
				x += 0.1;
			}else{
				if(winkel < 3.141){
					if(sceneHandler->kuhCam){
						sceneHandler->setCenterX(sceneHandler->getCenterX()-5);
					}
					winkel += 0.01;
				}else{
					vor = false;
				}
			}
		}else{
			if(x > 0.0){
				if(sceneHandler->kuhCam){
					sceneHandler->setEyeZ(6.5);
					sceneHandler->setEyeY(-80.5);
					sceneHandler->setEyeX(x+30);
					sceneHandler->setCenterX(-700);
				}
				x -= 0.1;
			}else{
				if(winkel > 0.0){
					if(sceneHandler->kuhCam){
						sceneHandler->setCenterX(sceneHandler->getCenterX()+5);
					}
					winkel -= 0.01;
				}else{
					vor = true;
				}
			}
		}
		mT.makeTranslate( x+30, -80., 3.25 );
		mR.makeRotate( winkel, osg::Vec3( 0., 0., 1. ) );
		mtLeft->setMatrix( mR * mT );
	}
	// um weitere callbacks aufzurufen
    traverse(node, nv); 
}
